package mapper;

import org.apache.ibatis.annotations.*;
import po.User;

import java.util.List;

/**
 * Created by Administrator on 2018/1/3.
 */
/*使用注解的方式完成CURD
* 使用注解的方式可以不用写mapper.xml文件
* useGeneratedKeys:表示的是主键自动产生*/
public interface UserAnnotationMapper {
    //添加一个用户
    @Insert("insert into user(id,username,birthday,sex,address) VALUE (#{id},#{username},#{birthday},#{sex},#{address})")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    void addUser(User user);
    /**
     * 查询所有用户
     * @return
     * */
    @Select("select * from user")
    List<User> findAllUser();
    /**
     * */
    @Select("SELECT * from USER WHERE id = #{id}")
    @Results({
            @Result(id = true ,column = "uid",property = "id"),
            @Result(column = "un" ,property = "username")
    })
    User findById(@Param("id")int uid);
}
